Skip to content

Conversation

@shreefAhmedM
Copy link

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Her is JavaScript challenges tasks covering running Jest test, error fixing, code interpretation, and a stretch exploration activity.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 12, 2025
// console.log(value);
// }
// It will log syntax Error because Objects themselves aren’t directly iterable Unlike arrays we need to converted
// and then we can loop

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good explanation — you clearly identified why the original loop didn't work and how to resolve it. @shreefAhmedM

// it will log [object Object].
console.log(`${recipe.title} serves ${recipe.serves}`);
console.log("ingredients");
recipe.ingredients.forEach((ingredient) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using forEach is a clean and readable way to loop through the ingredients. Good choice.

// When passed to contains with a non-existent property name
// Then it should return false

test("Given an object with none-existing property should return false", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very Good!

function contains() {}

function contains(obj, prop) {
return obj && typeof obj === "object" && prop in obj;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you safeguard against non-object inputs by checking typeof obj === "object". It makes the function more robust and prevents errors when unexpected values are passed in.

// is trying to access a property using address[0] and address is an object, not an array.
// it will log undefined.
// to access the houseNumber property, we should use dot notation or bracket notation with string,and either
// way using object.key or object["key"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @shreefAhmedM!
I think we can simplify the comment a bit.

// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("Given an object with an existing property should return true", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shreefAhmedM Good test — small mismatch: the acceptance criteria describe invalid parameters (like an array), but the test title says it's testing an object with an existing property.

@@ -1,3 +1,5 @@
function contains() {}

function contains(obj, prop) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shreefAhmedM we can make the argument prop more descriptive

@@ -1,5 +1,15 @@
function createLookup() {
// implementation here
function createLookup(nestedArr) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job — this works and produces the correct result! 👍
One suggestion: flattening the array isn’t necessary here, since the input is already a 2D array of [country, currency] pairs.
We can make the implementation simpler by iterating directly over each pair and assigning the key-value in the object. This keeps the code readable and avoids potential issues with unexpected nested arrays.

return result;
}

createLookup([

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t need to call createLookup here in the module. The tests will call it with the required inputs

// Given an array with duplicate items
// When passed to tally
// Then it should return counts for each unique item
test("Given a function tally(['a']), target output should be { a: 1 }", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make the test name align with the test requirement

// Given an empty array
// When passed to tally
// Then it should return an empty object
test.todo("tally on an empty array returns an empty object");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test.todo is only a placeholder. Once you implement the real test for an empty array, you can remove this line.

// When passed an array of items
// Then it should return an object containing the count for each unique item

test("Given a function tally(['a']), target output should be { a: 1 }", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test title and implementation don’t align.

function countWords(str) {
const obj = {};
let tidyStr = str.replace(/[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/g, "");
let arr = tidyStr.toLowerCase().split(" ");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking — splitting by " " only handles regular spaces. It won’t handle tabs (\t) or multiple consecutive spaces correctly. Can we think of a way to handle this?


// Find the value with the highest frequency
// Find the value with the highest frequency
function highestFreg(freqs) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shreefAhmedM Consider renaming highestFreg to highestFreq to fix the typo.

@jaymes15 jaymes15 added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants